<template>
  <div>
    <a-input placeholder="请输入任务" class="my_ipt" :value="inputValue" @change="handleInputChange" />
    <a-button type="primary" @click="addItemToList">添加事项</a-button>

    <a-list bordered :dataSource="infolist" class="dt_list">
      <a-list-item slot="renderItem" slot-scope="scope">
        <!-- 复选框 -->
        <a-checkbox :checked='scope.done' @change="checkChange($event,scope.id)">
            {{scope.info}}
        </a-checkbox>
        <!-- 删除链接 -->
        <a slot="actions" @click="delete1(scope.id)">删除</a>
      </a-list-item>

      <!-- footer区域 -->
      <div slot="footer" class="footer">
        <!-- 未完成的任务个数 -->
        <!-- <span>{{unDoneLength}}条剩余</span> -->
        <span>{{unDoneLength}}条剩余</span>
        <!-- 操作按钮 -->
        <a-button-group>
          <a-button @click="changeList('all')">全部</a-button>
          <a-button @click="changeList('undone')">未完成</a-button>
          <a-button @click="changeList('done')">已完成</a-button>
        </a-button-group>
        <!-- 把已经完成的任务清空 -->
        <a @click="clean">清除已完成</a>
      </div>
    </a-list>
  </div>
</template>
<script>
import { mapState,mapGetters } from "vuex";
export default {
  methods: {
      //input框change事件函数
    handleInputChange(e) {
        // console.log(e)
        this.$store.commit('setInputValue', e.target.value)
    },
    //点击添加按钮
    addItemToList(){
        console.log(this.inputValue)
        this.$store.commit('addInfoList',this.inputValue)
    },
    delete1(id){
      this.$store.commit('del',id)
    },
    checkChange(e,id){
        // console.log(e.target.checked);
        // console.log(id);
        this.$store.commit('buzhidao',{flhg:e.target.checked,id})
    },
    clean(){
        this.$store.commit('delAll')
    },
    changeList(key){
        this.$store.commit('changeList',key)
    }
  },
  computed: {
    ...mapState(["infolist", "inputValue"]),
    ...mapGetters(['unDoneLength', 'infolist'])
  },
  created() {
    this.$store.dispatch("getList");
  }
}
</script>
<style scoped>
.my_ipt {
  width: 500px;
  margin-right: 10px;
}

.dt_list {
  width: 500px;
  margin-top: 10px;
}

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
